From ab02efd4224aa4b15e99139a189dfbff91524dee Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Wed, 17 Mar 2004 15:24:30 +0000 Subject: [PATCH] (1) Points that coincide with a polygon vertex are now inside the polygon by fiat. (2) Fixed bug in intersection detector when test point was inside segment bbox --- gpsbabel/polygon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gpsbabel/polygon.c b/gpsbabel/polygon.c index da35b7683..3835f7de0 100644 --- a/gpsbabel/polygon.c +++ b/gpsbabel/polygon.c @@ -38,6 +38,7 @@ static char *exclopt = NULL; typedef struct { unsigned short state; + unsigned short override; } extra_data; static @@ -163,7 +164,7 @@ static void polytest ( double lat1, double lon1, } else if (!(lon1 <= lon3 && lon2 <= lon3)) { /* we're inside the bbox of a diagonal line. math time. */ - double loni = (lon2-lon1)/(lat2-lat1)*(lat3-lat1); + double loni = lon1+(lon2-lon1)/(lat2-lat1)*(lat3-lat1); if ( loni > lon3 ) { *state = *state ^ INSIDE; } @@ -221,8 +222,13 @@ polygon_process(void) else { ed = xcalloc(1, sizeof(*ed)); ed->state = OUTSIDE; + ed->override = 0; waypointp->extra_data = ed; } + if ( lat2 == waypointp->latitude && + lon2 == waypointp->longitude ) { + ed->override = 1; + } if ( olat != BADVAL && olon != BADVAL && olat == lat2 && olon == lon2 ) { last = 1; @@ -263,6 +269,7 @@ polygon_process(void) ed = wp->extra_data; wp->extra_data = NULL; if ( ed ) { + if ( ed->override ) ed->state = INSIDE; if (((ed->state & INSIDE) == OUTSIDE ) == (exclopt == NULL)) { waypt_del(wp); waypt_free(wp); -- 2.30.2